package com.sino.operation.system.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.sino.operation.commons.response.CenterResponseEntity;
import com.sino.operation.entity.BizDictSet;
import com.sino.operation.entity.SysDict;
import com.sino.operation.entity.SysTeller;
import com.sino.operation.service.BizDictSetService;
import com.sino.operation.service.SysDictService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@Slf4j
@RestController
@RequestMapping("dictManage")
@Api(value = "字典管理", tags = "字典管理")
public class DictManagerController {

    @Autowired
    private SysDictService sysDictService;

    @GetMapping("/selectDictList")
    @ApiOperation(value = "查询字典列表")
    @ResponseBody
    public IPage<SysDict> getDictSetList(@RequestParam Map<String,String> map){

        return sysDictService.selectList(map);
    }

    @PostMapping("/addDict")
    @ApiOperation(value = "新增字典配置数据")
    @ResponseBody
    public CenterResponseEntity addDictSet(SysDict sysDict){
        try {
            sysDictService.saveOrUpdate(sysDict);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return CenterResponseEntity.build();
    }

    @PostMapping("/deleteDict")
    @ApiOperation(value = "批量删除字典配置")
    @ResponseBody
    public CenterResponseEntity deleteDict(List ids){
        try {
            sysDictService.removeByIds(ids);
        } catch (Exception e) {
            e.printStackTrace();
            return CenterResponseEntity.buildError();
        }
        return CenterResponseEntity.build();
    }


    @PostMapping("/updateDict")
    @ApiOperation(value = "修改字典信息")
    @ResponseBody
    public CenterResponseEntity updateDictSet(SysDict sysDict){
        try {
            sysDictService.saveOrUpdate(sysDict);
        } catch (Exception e) {
            e.printStackTrace();
            return CenterResponseEntity.buildError();
        }
        return CenterResponseEntity.build();
    }
}
